<?php

if (is_numeric($_POST['parent_id'])) {
	$sort = $db->fetchOne("SELECT MAX(sort) FROM shop_categories WHERE parent_id=?", $_POST['parent_id']) + 10;
	$db->insert('shop_categories', array('site_id' => $site['id'], 'parent_id' => $_POST['parent_id'], 'sort' => $sort, 'title' => 'Untitled category'));
	$category_id = $db->lastInsertId();
	header('Content-type: application/json');
	echo json_encode(array('id' => $category_id));
}
